package com.xuan.contest.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xuan.contest.common.cache.CacheFactory;
import com.xuan.contest.dao.ProblemMapper;
import com.xuan.contest.entry.ProblemEntity;
import com.xuan.contest.service.IProblemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author XinZhaoXuan
 * @date 2018/9/7
 */
@Service
public class ProblemServiceImpl extends ServiceImpl<ProblemMapper, ProblemEntity> implements IProblemService {

    @Autowired
    private ProblemMapper problemMapper;
    /**
     * 根据问题查找正确答案
     *
     * @param questionId
     * @return
     */
    @Override
    public Integer selectAnswerByQuestion(int questionId) {
        Integer answer = CacheFactory.redisCache().getCacheObject(CacheFactory.PROBLEM_ANSWER + questionId);

        if (answer == null) {
            answer = problemMapper.selectAnswerByQuestion(questionId);

            CacheFactory.redisCache().setCacheObject(CacheFactory.PROBLEM_ANSWER + questionId, answer);
        }


        return answer;
    }
}
